package com.neuedu.elmserver.controller;


import com.neuedu.elmserver.pojo.Address;
import com.neuedu.elmserver.pojo.Cart;
import com.neuedu.elmserver.service.AddressService;
import com.neuedu.elmserver.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 收货地址 前端控制器
 * </p>
 *
 * @author wyh
 * @since 2024-11-11
 */
@RestController
@RequestMapping("/address")
@CrossOrigin
public class AddressController {
    @Autowired
    private AddressService addressService;

    /**
     * 新增收货地址
     * @param address
     * @return
     */
    @PostMapping("/addAddress")
    public ResultVO addAddress(@RequestBody Address address){
        return addressService.saveAddress(address);
    }

    /**
     * 查询指定用户的收货地址列表
     * @param userId
     * @return
     */
    @GetMapping("/listAddressByUser")
    public ResultVO listAddressByUser(Integer userId){
        return addressService.queryAddressByUser(userId);
    }

    /**
     * 更新收货地址
     * @param address
     * @return
     * @RequestBody:将请求体(请求参数)的JSON数据类型转为Java对象
     */
    @PostMapping("/editAddress")
    public ResultVO editAddress(@RequestBody Address address){
        return addressService.editAddress(address);
    }

    /**
     * 删除收货地址
     * @param address
     * @return
     */
    @PostMapping("/deleteAddress")
    public ResultVO deleteAddress(@RequestBody Address address){
        return addressService.deleteAddress(address);
    }
}
